/* Copyright (C) 2005-2013, Unigine Corp. All rights reserved.
 *
 * File:    fragment_surface_light.h
 * Desc:    Water surface light shader
 * Version: 1.02
 * Author:  Alexander Zapryagaev <frustum@unigine.com>
 *
 * This file is part of the Unigine engine (http://unigine.com/).
 *
 * Your use and or redistribution of this software in source and / or
 * binary form, with or without modification, is subject to: (i) your
 * ongoing acceptance of and compliance with the terms and conditions of
 * the Unigine License Agreement; and (ii) your inclusion of this notice
 * in any version of this software that you use or redistribute.
 * A copy of the Unigine License Agreement is available by contacting
 * Unigine Corp. at http://unigine.com/
 */

/******************************************************************************\
*
* OpenGL/OpenGLES
*
\******************************************************************************/

#ifdef OPENGL || OPENGLES
	
	#ifndef FRAGMENT_BASE_LIGHT
		#define FRAGMENT_BASE_LIGHT
		
		uniform sampler2D s_texture_0;
		uniform sampler2D s_texture_1;
		uniform sampler2D s_texture_2;
		uniform sampler2D s_texture_3;
		
		uniform fixed3 s_water_tangent;
		uniform fixed3 s_water_binormal;
		
		uniform float4 normal_0_transform;
		uniform float4 normal_1_transform;
		uniform float4 normal_2_transform;
		uniform float4 normal_3_transform;
		uniform float4 foam_0_transform;
		uniform float4 foam_1_transform;
		uniform float4 caps_0_transform;
		uniform float4 caps_1_transform;
		uniform fixed reflection_normal;
		uniform fixed4 reflection_0_color;
		uniform fixed4 surface_color;
		uniform fixed4 foam_color;
		uniform fixed foam_scale;
		uniform fixed foam_threshold;
		uniform half foam_falloff;
		uniform fixed4 caps_color;
		uniform fixed caps_scale;
		uniform fixed caps_threshold;
		
	#else
		
		#include <core/shaders/simple/water/fragment_surface_normal.h>
		
		#ifdef WORLD
			fixed3 light_direction = s_light_direction;
		#else
			fixed3 light_direction = normalize(s_texcoord_3.xyz);
		#endif
		fixed3 camera_direction = normalize(s_texcoord_4.xyz);
		
		fixed fresnel = getFresnel(s_material_fresnel,normal,camera_direction);
		
		fixed3 color = getDiffuse(s_material_shading,surface_color.xyz,normal,light_direction) * (1.0f - fresnel);
		
		color += getSpecular(s_material_shading,reflection_0_color.xyz,normal,light_direction,camera_direction);
		
	#endif
	
/******************************************************************************\
*
* Direct3D11/Direct3D119
*
\******************************************************************************/

#elif DIRECT3D11 || DIRECT3D119
	
	#ifndef FRAGMENT_BASE_LIGHT
		#define FRAGMENT_BASE_LIGHT
		
		Texture2D s_texture_0 : register(t0);
		Texture2D s_texture_1 : register(t1);
		Texture2D s_texture_2 : register(t2);
		Texture2D s_texture_3 : register(t3);
		
		cbuffer shader_water_parameters {
			float3 s_water_tangent;
			float3 s_water_binormal;
		};
		
		cbuffer shader_parameters {
			#ifdef OMNI || PROJ
				float4 normal_0_transform;
				float4 normal_1_transform;
				#ifdef QUALITY_MEDIUM
					float4 normal_2_transform;
					float4 normal_3_transform;
				#endif
			#endif
			float reflection_normal;
			float4 reflection_0_color;
			float4 surface_color;
			#ifdef FOAM
				float4 foam_0_transform;
				float4 foam_1_transform;
				float4 foam_color;
				float foam_scale;
				float foam_threshold;
				float foam_falloff;
			#endif
			#ifdef CAPS
				float4 caps_0_transform;
				float4 caps_1_transform;
				float4 caps_color;
				float caps_scale;
				float caps_threshold;
			#endif
		};
		
	#else
		
		#include <core/shaders/simple/water/fragment_surface_normal.h>
		
		#ifdef WORLD
			half3 light_direction = s_light_direction;
		#else
			half3 light_direction = normalize(IN.texcoord_3.xyz);
		#endif
		half3 camera_direction = normalize(IN.texcoord_4);
		
		half fresnel = getFresnel(s_material_fresnel,normal,camera_direction);
		
		half3 color = getDiffuse(s_material_shading,surface_color.xyz,normal,light_direction) * (1.0f - fresnel);
		
		color += getSpecular(s_material_shading,reflection_0_color.xyz,normal,light_direction,camera_direction);
		
	#endif
	
#endif
